package com.whh.spring.ioc.beans.support;

import com.whh.spring.ioc.beans.BeanFactory;
import com.whh.spring.ioc.beans.config.BeanDefinition;

public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {
    @Override
    public Object getBean(String beanName) {
        Object singleton = getSingleton(beanName);
        if (singleton == null) {
            singleton = createBean(beanName,getBeanDefinition(beanName));
        }
        addSingleton(beanName, singleton);
        return singleton;
    }


    protected abstract Object createBean(String beanName, BeanDefinition beanDefinition);

    protected abstract BeanDefinition getBeanDefinition(String beanName);

    @Override
    public <T> T getBean(String beanName, Class<T> requiredType) {
        return null;
    }
}
